#!c:/usr/perl

##########################
#     OmnibusProxy       #
#    Krzysztof Ulman     #
# Politechnika Krakowska #
#      Kraków 2012       #
##########################

use strict;
use warnings;
use encoding 'utf8';

use LWP::Simple;
use WWW::Mechanize;
use Try::Tiny;

our $URL = 'http://automation.whatismyip.com/n09230945.asp';

#my $data = get($URL);
my $data;

#INFO: http://probably.co.uk/installing-perl-wwwmechanize-when-behind-a-proxy.html
my $browser = WWW::Mechanize->new();
$browser->proxy(['http', 'https'], 'http://corp-200-105-245-236-uio.punto.net.ec:8080');
#$browser->proxy('http', 'http://host-91-103-29-85.customers.adc.am:8080');
#$browser->proxy('http', 'http://krzys487:sciencedirect@mars.iti.pk.edu.pl:3128');

#eval {
#	$browser->get($URL);
#};
#if($@) {
#	print "Blad podczas laczenia\n";
#	my $value = $@;
#	my $a = 5;	 
#	# local $_ = $@;
#    # &$catch;
#}

try {
	my $a = 5;
	$browser->get($URL);
} catch {
	my $exception = $_;
	print $exception . "\n";
};

if($browser->success()) {
	$data = $browser->content();
}


if($data) {
	
	if($data =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
	
		print "$data\n";
	}
	
} else {
	print "nie pobrano\n";
}



print "\n\nKoniec";